package com.nd.rj.common.login;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import com.product.android.business.config.Configuration;

public class GlobalSetting {

	/**************** 网络环境 *************************/
	public static final int NETWORK_IN = 2; // 内网
	public static final int NETWORK_SIMULATE = 1; // 模拟环境
	public static final int NETWORK_OUT = 0; // 外网

	private int mNetworkEnv = NETWORK_OUT;
	private String mAppid="";
	private int mSiteflat;
	private String mUapAppid="";

	private static GlobalSetting mInstance;

	public static GlobalSetting getInstance(Context context) {
		if (mInstance == null) {
			mInstance = new GlobalSetting();
		}
		if (TextUtils.isEmpty(mInstance.mAppid)) {
			mInstance.getParam(context);
		}
		return mInstance;
	}

	private void getParam(Context context) {
		// Activity activity=(Activity)context;
		ApplicationInfo appInfo;
		try {
			appInfo = context.getPackageManager().getApplicationInfo(
					context.getPackageName(), PackageManager.GET_META_DATA);
			Bundle bundle = appInfo.metaData;
			Object object=bundle.get("APPID");
//			if (object!=null){
//				if (object instanceof String){
//					mAppid=(String) object;
//				}else if (object instanceof Integer){
//					mAppid=object.toString();
//				}	
//			}
			mAppid=Configuration.OAP_APPID+"";
			object =bundle.get("UAPAPPID");
			if (object!=null){
				if (object instanceof String){
					mUapAppid=(String) object;
				}else if (object instanceof Integer){
					mUapAppid=object.toString();
				}	
			}
			mSiteflat = bundle.getInt("SITEFLAT", 0);
			mNetworkEnv = Configuration.DEBUG?NETWORK_IN:NETWORK_OUT;
			Log.d("debug", "======" + "APPID:" + mAppid + ",UAPAPPID="
					+ mUapAppid + ",SITEFLAT=" + mSiteflat + ",network="
					+ mNetworkEnv);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
	}

	public int getNetworkEnv() {
		return mNetworkEnv;
	}

	public int getSiteflat() {
		return mSiteflat;
	}

	public String getAppid() {
		return mAppid;
	}

	public String getUapAppid() {
		return mUapAppid;
	}
}
